﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Simhopp.Model
{
    public class Dive : InterfaceDiveModel
    {
        public int ID { get; set; }
        public int C_ID { get; set; }
        public int D_ID { get; set; }
        public string Name { get; set; }
        public double Difficulty { get; set; }
        public string NameCode { get; set; }
        public double Score { get; set; }
        public int DiveNumber { get; set; }
        public Dictionary<int, double> JudgeScore {get; set;}

        public Dive()
        {
            this.ID = 0;
            this.C_ID = 0;
            this.D_ID = 0;
            this.Name = "";
            this.Difficulty = 0;
            this.NameCode = "";
            this.Score = 0;
            this.DiveNumber = 0;
            this.JudgeScore = new Dictionary<int, double>();
        }
        public Dive(int DiveID, string name, int DiveNumber)
        {
            this.ID = DiveID;
            this.C_ID = 0;
            this.D_ID = 0;
            this.Name = name;
            this.Difficulty = 0;
            this.NameCode = "";
            this.Score = 0;
            this.DiveNumber = DiveNumber;
            this.JudgeScore = new Dictionary<int, double>();
        }
        public Dive(int ID, int D_ID, int C_ID, string Name, double Difficulty, string NameCode, int DiveNumber)
        {
            this.ID = ID;
            this.D_ID = D_ID;
            this.C_ID = C_ID;
            this.Name = Name;
            this.Difficulty = Difficulty;
            this.NameCode = NameCode;
            this.Score = 0;
            this.DiveNumber = DiveNumber;
            this.JudgeScore = new Dictionary<int, double>();
        }
        
        public void AddDiveResult(int Score)
        {
            this.Score = Score;
        }
        public void CalculateDiveScore()
        {
            double max = 0;
            double min = 10;

            foreach (var judge in JudgeScore)
            {
                if (judge.Value > max)
                    max = judge.Value;
                if (judge.Value < min)
                    min = judge.Value;
                this.Score += judge.Value;
            }
            this.Score = ((this.Score - max - min) * this.Difficulty);
        }
    }
}

